import type {ValueOf} from 'type-fest';
import CONST from '@src/CONST';
import type {ConnectionName} from '@src/types/onyx/Policy';

const ROUTE_NAME_MAPPING = {
    [CONST.POLICY.CONNECTIONS.ROUTE.QBO]: CONST.POLICY.CONNECTIONS.NAME.QBO,
    [CONST.POLICY.CONNECTIONS.ROUTE.XERO]: CONST.POLICY.CONNECTIONS.NAME.XERO,
    [CONST.POLICY.CONNECTIONS.ROUTE.SAGE_INTACCT]: CONST.POLICY.CONNECTIONS.NAME.SAGE_INTACCT,
    [CONST.POLICY.CONNECTIONS.ROUTE.NETSUITE]: CONST.POLICY.CONNECTIONS.NAME.NETSUITE,
    [CONST.POLICY.CONNECTIONS.ROUTE.QBD]: CONST.POLICY.CONNECTIONS.NAME.QBD,
};

const NAME_ROUTE_MAPPING = {
    [CONST.POLICY.CONNECTIONS.NAME.QBO]: CONST.POLICY.CONNECTIONS.ROUTE.QBO,
    [CONST.POLICY.CONNECTIONS.NAME.XERO]: CONST.POLICY.CONNECTIONS.ROUTE.XERO,
    [CONST.POLICY.CONNECTIONS.NAME.SAGE_INTACCT]: CONST.POLICY.CONNECTIONS.ROUTE.SAGE_INTACCT,
    [CONST.POLICY.CONNECTIONS.NAME.NETSUITE]: CONST.POLICY.CONNECTIONS.ROUTE.NETSUITE,
    [CONST.POLICY.CONNECTIONS.NAME.QBD]: CONST.POLICY.CONNECTIONS.ROUTE.QBD,
};

function getConnectionNameFromRouteParam(routeParam: ValueOf<typeof CONST.POLICY.CONNECTIONS.ROUTE>) {
    return ROUTE_NAME_MAPPING[routeParam];
}

function getRouteParamForConnection(connectionName: ConnectionName) {
    return NAME_ROUTE_MAPPING[connectionName];
}

export {getConnectionNameFromRouteParam, getRouteParamForConnection};
